package com.entrogy.dao;

import com.alibaba.fastjson.JSONObject;
import com.entrogy.bean.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @ClassName StudentAttendanceMapper
 * @Description
 * @Author luoxingjiang
 * @Date 2019/7/17 0017 上午 10:51
 * @Version 1.0
 **/
@Repository
public interface StudentAttendanceMapper {


    /**
     * 查询年级考勤时间信息
     * @param schoolCode
     * @return
     */
    GradeAttendanceTimeEntity getGradeMorningAttendanceTime(@Param("schoolCode") Integer schoolCode, @Param("gradeId") Integer gradeId);

    /**
     * 添加年级考勤信息
     * @param gradeAttendanceTime
     * @return
     */
    Integer addGradeAttendanceInfo(GradeAttendanceTimeEntity gradeAttendanceTime);

    /**
     * 更新年级考勤信息
     * @param gradeAttendanceTime
     * @return
     */
    Integer updateGradeAttendanceInfo(@Param(value = "gradeAttendanceTime") List<GradeAttendanceTimeEntity> gradeAttendanceTime);

    /**
     * 查询某个班级在规定的早上考勤时段内没有在大门口的设备打卡的走读生的人数
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @param noonStartTime
     * @return
     */
    List<Integer> countMorningLateStudentByNoPassRecord(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "tableName") String tableName, @Param("gradeId") Integer gradeId, @Param("noonStartTime") String noonStartTime);

    /**
     * 得到要考勤班级的基本信息
     * @param classId
     * @param schoolCode
     * @return
     */
    ClassAttendanceEntity getClassInfo(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode);

    /**
     * 得到某个班级早上的考勤时间
     * @param classId
     * @param schoolCode
     * @return
     */
    JSONObject getClassMorningAttendanceTime(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode);

    /**
     * 得到某一天某个班级的请假人数
     * @param classId
     * @param time
     * @param schoolCode
     * @param gradeId
     * @return
     */
    List<Integer> countAskForLeaveStudent(@Param(value = "classId") Integer classId, @Param(value = "time") Date time, @Param(value = "schoolCode") Integer schoolCode, @Param("gradeId") Integer gradeId);

    /**
     * 查找该班级中午的考勤时段
     * @param classId
     * @param schoolCode
     * @param dynArrangeTableName
     * @return
     */
    String getClassNoonAttendanceTime(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "dynArrangeTableName") String dynArrangeTableName);

    /**
     * 统计中午要出去的学生但是在中午考勤时段内只有一条在出门设备上通行记录的学生人数
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @return
     */
    List<Integer> countClassNoonLateStudentByHasOnePassRecord(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "tableName") String tableName, @Param("gradeId") Integer gradeId);

    /**
     * 中午进出校次数总和为单数的人数
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @return
     */
    List<Integer> countClassNoonLateStudentByHasOddPassRecord(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "tableName") String tableName, @Param("gradeId") Integer gradeId);

    /**
     * 查找该班级下午的考勤时段
     * @param classId
     * @param schoolCode
     * @param dynArrangeTableName
     * @return
     */
    String getClassAfternoonAttendanceTime(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "dynArrangeTableName") String dynArrangeTableName);

    /**
     * 统计下午要出去的学生但是在下午考勤时段内只有一条在出门设备上通行记录的学生人数
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @return
     */
    List<Integer> countClassAfterNoonLateStudentByHasOnePassRecord(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "tableName") String tableName, @Param("gradeId") Integer gradeId);

    /**
     * 下午进出校次数总和为单数的人数
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @return
     */
    List<Integer> countClassAfternoonLateStudentByHasOddPassRecord(@Param(value = "classId") Integer classId, @Param(value = "schoolCode") Integer schoolCode, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "tableName") String tableName, @Param("gradeId") Integer gradeId);

    /**
     * 根据学生id查询这些学生的考勤异常信息
     * @param lateStudentIds
     * @param tableName
     * @param endTime
     * @param noonStartTime
     * @return
     */
    List<AttendanceExceptionStudentEntity> listAttendanceExceptionStudentInfo(@Param(value = "lateStudentIds") List<Integer> lateStudentIds, @Param(value = "tableName") String tableName, @Param(value = "endTime") String endTime, @Param("noonStartTime") String noonStartTime);

    /**
     * 根据学生id查询这些学生的请假信息
     * @param askForLeaveStudentIds
     * @param time
     * @return
     */
    List<AskForLeaveStudentEntity> listAskForLeaveStudentInfo(@Param(value = "askForLeaveStudentIds") List<Integer> askForLeaveStudentIds, @Param("time") Date time);

    /**
     * 返回年级列表
     * @param schoolCode
     * @return
     */
    List<GradeEntity> listGrade(@Param("schoolCode") Integer schoolCode);

    /**
     * 统计早上迟到学生的id
     * @param classId
     * @param schoolCode
     * @param startTime
     * @param endTime
     * @param tableName
     * @param gradeId
     * @param noonStartTime
     * @return
     */
    List<Integer> countMorningLateStudentPassRecord(@Param("classId") Integer classId, @Param("schoolCode") Integer schoolCode, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("tableName") String tableName, @Param("gradeId") Integer gradeId, @Param("noonStartTime") String noonStartTime);

    /**
     * 查询某个时间点后是否有进校通行记录
     * @param studentId
     * @param passEndTime
     * @param tableName
     * @return
     */
    List<Integer> listStudentPassRecord(@Param("studentId") Integer studentId, @Param("passEndTime") Date passEndTime, @Param("tableName") String tableName);

    /**
     * 查询年级中午的考勤时间
     * @param gradeId
     * @param schoolCode
     * @param dynArrangeTableName
     * @return
     */
    String getGradeNoonAttendanceTime(@Param("gradeId") Integer gradeId, @Param("schoolCode") Integer schoolCode, @Param("dynArrangeTableName") String dynArrangeTableName);

    /**
     * 查询年级下午的考勤时间
     * @param gradeId
     * @param schoolCode
     * @param dynArrangeTableName
     * @return
     */
    String getGradeAfternoonAttendanceTime(@Param("gradeId") Integer gradeId, @Param("schoolCode") Integer schoolCode, @Param("dynArrangeTableName") String dynArrangeTableName);

    /**
     * 查询学校所有年级早上的考勤时间
     * @param schoolCode
     * @return
     */
    List<GradeAttendanceTimeEntity> listGradeMorningAttendanceTime(Integer schoolCode);
}
